package com.diy.sigmund.diycommon.entity.base.exception;

import com.diy.sigmund.diycommon.entity.base.BaseEnumInterface;
import com.diy.sigmund.diycommon.entity.enumerate.ResponseEnum;

/**
 * @author ylm-sigmund
 * @since 2021/5/4 11:43
 */
public class DiyRuntimeException extends RuntimeException {

    /**
     * 错误码
     */
    protected String errorCode;
    /**
     * 错误信息
     */
    protected String errorMsg;

    public DiyRuntimeException() {
        super();
    }

    public DiyRuntimeException(String errorMsg) {
        super(errorMsg);
        this.errorCode = ResponseEnum.REQUEST_FAIL.getCode();
        this.errorMsg = errorMsg;
    }

    public DiyRuntimeException(BaseEnumInterface baseEnumInterface) {
        super(baseEnumInterface.getMsg());
        this.errorCode = baseEnumInterface.getCode();
        this.errorMsg = baseEnumInterface.getMsg();
    }

    public DiyRuntimeException(String errorCode, String errorMsg) {
        super(errorMsg);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public DiyRuntimeException(BaseEnumInterface baseEnumInterface, Throwable cause) {
        super(baseEnumInterface.getMsg(), cause);
        this.errorCode = baseEnumInterface.getCode();
        this.errorMsg = baseEnumInterface.getMsg();
    }

    @Override
    public synchronized Throwable fillInStackTrace() {
        return super.fillInStackTrace();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
}
